﻿

    
    function client_OnTreeNodeChecked()
    {
        var obj = window.event.srcElement;
        var treeNodeFound = false;
        var checkedState;
        if (obj.tagName == "INPUT" && obj.type == "checkbox")
        {
            var treeNode = obj;
            checkedState = treeNode.checked;
            do
            {
                obj = obj.parentElement;
            } while (obj.tagName != "TABLE")
            var parentTreeLevel = obj.rows[0].cells.length;
            var parentTreeNode = obj.rows[0].cells[0];
            var tables = obj.parentElement.getElementsByTagName("TABLE");
            var numTables = tables.length
            if (numTables >= 1)
            {
                for (i=0; i < numTables; i++)
                {
                    if (tables[i] == obj)
                    {
                        treeNodeFound = true;
                         i++;
                         if (i == numTables)
                        {
                            return;
                        }
                }
                if (treeNodeFound == true)
                {
                    var childTreeLevel = tables[i].rows[0].cells.length;
                    if (childTreeLevel > parentTreeLevel)
                    {
                        var cell = tables[i].rows[0].cells[childTreeLevel - 1];
                        var inputs = cell.getElementsByTagName("INPUT");
                        inputs[0].checked = checkedState;
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
        }
    }
    
//------------addDate(spanId,index,value)------------
function addDate(spanId,index,value)
{
       var strIndex = "" + index;
       var dateId = "k"+ strIndex;
       var brId = "idBr" + strIndex;
       
       addInputFile(spanId,dateId,value);
       adddel(spanId,index);
       addbr(spanId,brId);
       addbr(spanId,brId + "2");
       return;
}
//---------------sub function------------------
function addInputFile(spanId,inputId,value)
{
      var span = document.getElementById(spanId);
      if ( span !=null ) {
           if ( !IsIE ) {
                  var inputObj = document.createElement("input");
                  if ( inputObj != null ) {
                       inputObj.type="text";
                       inputObj.name = inputId;
                       inputObj.id = inputId;
                       inputObj.size="30";
                       var clickEvent = "exist('" + inputId + "')";
                       inputObj.setAttribute("onclick",clickEvent);
                       inputObj.setAttribute("class","Wdate");
                       inputObj.setAttribute("value",value);
                       inputObj.setAttribute("onfocus", new WdatePicker(this, '%Y-%M-%D' ,false));
                       span.appendChild(inputObj);
                      }//if inputObj
             }// !IsIE

             if ( IsIE ) {                  
                  var Tag = "<input type='text' class='Wdate' value='"+ value +"' onfocus=\"new WdatePicker(this, '%Y-%M-%D' ,false);\" name='" + inputId + "' size=30>";
                  var inputObj = document.createElement(Tag); 
                   span.appendChild(inputObj);
             }//IsIE if
      }//if span
}

//---------------添加换行----------------
function addbr(spanId,brId)
{
      var span = document.getElementById(spanId);
      if ( span !=null ) {
           var brObj = document.createElement("br");
           if ( brObj !=null ) {
                brObj.name = brId;
                brObj.id = brId;
                span.appendChild(brObj);
            }//if
      }//if
      return;
}
//---------------添加删除按钮------------------
function adddel(spanId,index)
{
      var strIndex = "" + index;
      var delId = "idOper" + strIndex;
      var span = document.getElementById(spanId);
      if ( span != null ) {
          var oTextNode = document.createElement("span");
          oTextNode.style.width = "5px";
          span.appendChild(oTextNode);
          if ( IsIE ) {
                var tag = "<input type='button' id='" + delId + "' class='wsd_button2' onclick=delInput('" + spanId + "',"+strIndex+")></input>";
                var delObj = document.createElement(tag);
                if ( delObj != null ) {
                      span.appendChild(delObj);
                }//if
           }// Is IE
                        
           if ( !IsIE ) {
                var delObj = document.createElement("input");
                if ( delObj != null ) {
                      delObj.name = delId;
                      delObj.id = delId;
                      delObj.type = "button";
                      delObj.setAttribute("class","wsd_button2");
                      var clickEvent = "return delInput('" + spanId + "',"+strIndex+");";
                      delObj.setAttribute("onclick",clickEvent);  
                      span.appendChild(delObj);
                  }//if
             }// !IsIE if
             if( delObj != null)
             {  delObj.value = "取  消";  }
      }//main if
      return;
}
//---------------delete input text--------------------
function delInput(spanId,index)
{
       var strIndex = "" + index;
       var fileId = "k"+ strIndex;
       var brId = "idBr" + strIndex;
       var delId = "idOper" + strIndex;
       //first,get the element
       var span = document.getElementById(spanId);
       //alert(  "del span: " + span  );
       if ( span == null ) return false;

       var fileObj = document.getElementById(fileId);
       if ( fileObj == null ) return false;

       var brObj = document.getElementById(brId);       
       if ( brObj ==null ) return false;
       var brObj2 = document.getElementById(brId + "2"); 

       var delObj = document.getElementById(delId );
       //alert(  "del delId: " + delObj  );
       if ( delObj == null ) return false;

       //second,create the replace element
       var temp= document.createElement("span");
       //third,replace it
       span.replaceChild(temp,fileObj);
       span.replaceChild(temp,brObj);
       span.replaceChild(temp,brObj2);       
       // Added by Henry
       span.removeChild(delObj.previousSibling);
       var Date = document.getElementById("Date");
       if(span.getElementsByTagName("input").length == 1) 
       {  Date.childNodes[0].nodeValue='添加假日';}
       // End
       span.replaceChild(temp,delObj);        
                
       return false;
}

